package main;

import java.io.File;

import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;

public class TaxRatioTableModel extends AbstractNItableModel {
	private float mLevyPoint = 2000;

	public float getLevyPoint() {
		return mLevyPoint;
	}

	public int getLevyLevel(float taxBase) {
		int result = 0;
		if (taxBase < 500) {
			result = 1;
		} else if (taxBase < 2000) {
			result = 2;
		} else if (taxBase < 5000) {
			result = 3;
		} else if (taxBase < 20000) {
			result = 4;
		} else if (taxBase < 40000) {
			result = 5;
		} else if (taxBase < 60000) {
			result = 6;
		} else if (taxBase < 80000) {
			result = 7;
		} else if (taxBase < 100000) {
			result = 8;
		} else {
			result = 9;
		}
		return result;
	}

	public float getCurrentTaxRatio(int levyLevel) {
		return Float.valueOf((String) getValue(Constant.tax_levyLevel,
				levyLevel, Constant.tax_taxRatio));
	}

	public float getQuickDeduction(int levyLevel) {
		return Float.valueOf((String) getValue(Constant.tax_levyLevel,
				levyLevel, Constant.tax_quickDeduction));
	}

	@Override
	public File createDataFile() {
		String filePath = System.getProperty("user.dir");
		return new File(filePath + "\\" + "taxData.txt");
	}

	@Override
	public Object getValue(String indexCol_headerName, Object cellValue,
			String headValue) {
		int targetRow = -1;
		int indexCol=-1;
		for (int col=0;col<getColumnCount();col++) {
			if (getColumnName(col).equals(indexCol_headerName)) {
				indexCol=col;
				break;
			}
		}
		
		for (int row = 0; row < getRowCount(); row++) {
			Object value = getValueAt(row, indexCol);
			if (Integer.valueOf((String) value).equals((Integer)cellValue)) {
				targetRow = row;
				break;
			}
		}

		int targetCol = -1;
		
		for (int col=0;col<getColumnCount();col++) {
			if (getColumnName(col).equals(headValue)) {
				targetCol=col;
				break;
			}
		}

		return getValueAt(targetRow, targetCol);
	}

}
